<template>
    <div class="checks">
        <el-checkbox-group v-model="checked" @change="handleCheckedChange" :max="max">
            <el-checkbox v-for="item in tags" :label="item" :key="item.id">{{ item.name }}</el-checkbox>
        </el-checkbox-group>
    </div>
</template>

<script>
import { mapState } from 'vuex'

export default {
    data() {
        return {
            checked: [],

            tags: null,
            defaultKey: 'vel_rms',
            max: 8,
        }
    },
    props: {
        sensorInfo: {
            type: Object,
            default: null,
        },
    },
    computed: {
        ...mapState('backstage', ['sys_eig']),
    },
    methods: {
        handleCheckedChange(e) {
            this.$emit('handleCheckedChange', e)
        },
        eigTimeChange(e) {
            this.$emit('eigTimeChange', e)
        },
        setDefaultKey(key) {
            this.defaultKey = key || ''
            let e = this.tags.filter((e) => e.nickname == this.defaultKey)
            if (e.length != 0) {
                this.checked = e
                this.$emit('handleCheckedChange', e)
            }
        },
        setEigtags(sensorInfo) {
            if (sensorInfo.sys_eig) {
                const arr1 = sensorInfo.sys_eig.split(',').map(Number)
                this.tags = this.sys_eig.filter((item) => arr1.includes(item.id))
                let e = this.tags.filter((e) => e.nickname == this.defaultKey)
                if (e.length != 0) this.checked = e
                else {
                    e = [this.tags[0]]
                    this.checked = e
                }
                this.$emit('handleCheckedChange', e)
            }
        },
        clearChecked() {
            this.checked.splice(0, this.checked.length)
        },
    },
    created() {},
}
</script>

<style lang="less" scoped>
.checks {
    width: 80%;
    margin-left: 10%;
}

.el-date-editor--datetimerange.el-input__inner {
    width: 100%;
}

.el-checkbox-group {
    display: flex;
    flex-direction: column;
}
</style>
